{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "import mlearn\n",
    "import torch\n",
    "import mlearn.functional as F\n",
    "from mlearn.layers import Dense, Conv2d\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "a = np.random.randn(3,4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 0.827235    0.36828696  0.65171885  1.65491882]\n",
      " [ 2.17868364 -0.47446996  1.02801935  0.14106531]\n",
      " [-0.95886884 -0.74322281 -0.0788397   1.14600784]]\n"
     ]
    }
   ],
   "source": [
    "print(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "class Net(mlearn.Module):\n",
    "    def __init__(self):\n",
    "        super(Net,self).__init__()\n",
    "        self.conv1 = Conv2d(3,8,5,5)\n",
    "        self.conv2 = Conv2d(8,8,5,5)\n",
    "        self.dense = Dense(20,5)\n",
    "        \n",
    "        \n",
    "    def forward(self, inputs):\n",
    "        return conv1(inputs)\n",
    "net = Net()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "OrderedDict([('conv1', 二维卷积Object -> ( 3, 8, kernel_size=(5, 5), stride=5 ) ),\n",
       "             ('conv2', 二维卷积Object -> ( 8, 8, kernel_size=(5, 5), stride=5 ) ),\n",
       "             ('dense', 全连接层 -> ( Batch Size, 20) => (Batch Size, 5 ))])"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "net._modules"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'_modules': OrderedDict([('conv1',\n",
       "               二维卷积Object -> ( 3, 8, kernel_size=(5, 5), stride=5 ) ),\n",
       "              ('conv2', 二维卷积Object -> ( 8, 8, kernel_size=(5, 5), stride=5 ) ),\n",
       "              ('dense', 全连接层 -> ( Batch Size, 20) => (Batch Size, 5 ))]),\n",
       " '_parameters': OrderedDict()}"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "net.__dict__"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "二维卷积Object -> ( 3, 8, kernel_size=(5, 5), stride=5 ) "
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "net.__dict__['_modules']['conv1']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "OrderedDict([('weights', 可訓練的參數\n",
       "              Tensor([[-0.2891,  1.0286,  0.3472, -0.0188,  0.4378],\n",
       "                      [-0.1112, -0.1764, -0.0156, -0.5593, -0.5181],\n",
       "                      [ 0.2446,  0.5748, -0.5268, -0.1835,  0.3648],\n",
       "                      [ 0.3279,  0.5587,  0.3092, -0.7850, -0.1135],\n",
       "                      [-0.0363,  0.1224, -0.5291, -0.2516,  0.2991],\n",
       "                      [ 0.0195, -1.0720, -0.0091,  0.4636, -0.6655],\n",
       "                      [ 0.2097, -0.5552,  0.2976, -0.8054,  0.0072],\n",
       "                      [ 0.0826, -0.4075,  0.0093,  0.1670,  0.2445],\n",
       "                      [-0.1658, -0.1218,  0.3129, -0.1572, -0.0271],\n",
       "                      [-0.0338, -0.0160,  0.3908, -0.1960,  0.1757],\n",
       "                      [-0.0902, -0.2091, -0.2020,  0.4809, -0.1964],\n",
       "                      [-0.1758, -0.4600, -0.4503, -0.3117, -0.2646],\n",
       "                      [ 0.7576, -0.7371,  0.9362, -0.3658, -0.4534],\n",
       "                      [ 0.1287,  0.8042, -1.0431,  0.6031, -0.4506],\n",
       "                      [-0.5096, -0.0234, -0.0164,  0.2515, -0.2784],\n",
       "                      [ 0.2395,  0.0453,  0.2460,  0.1911,  0.2369],\n",
       "                      [ 0.0234, -0.8267,  0.2676,  0.5151, -0.3774],\n",
       "                      [-0.0935, -0.0879,  0.7846,  0.8310, -0.1624],\n",
       "                      [ 0.3174, -0.1523, -0.3826,  0.2558, -0.1900],\n",
       "                      [-0.8222,  0.2696, -0.4794, -0.0340, -0.6325]], requires_grad=True)),\n",
       "             ('bias', 可訓練的參數\n",
       "              Tensor([ 0.0501, -0.2181, -0.4897, -0.2586, -0.4804], requires_grad=True))])"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "net.__dict__['_modules']['dense']._parameters"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
